home *** CD-ROM | disk | FTP | other *** search
/ Treccani Italiana Di Scienze Lettere Ed Arti / [Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso / pc / data / xxi_appendice_dvd.swf / scripts / __Packages / CTooltipManager.as < prev    next >
Text File  |  2007-11-08  |  9KB  |  281 lines

  1. class CTooltipManager
  2. {
  3.    var hookPrefix = "old_";
  4.    function CTooltipManager()
  5.    {
  6.    }
  7.    static function getInstance()
  8.    {
  9.       if(CTooltipManager._INSTANCE == null)
  10.       {
  11.          CTooltipManager._INSTANCE = new CTooltipManager();
  12.       }
  13.       return CTooltipManager._INSTANCE;
  14.    }
  15.    function init(target, depth)
  16.    {
  17.       this.container_mc = target.createEmptyMovieClip("container_mc" + depth,depth);
  18.       this._showShadow = false;
  19.       this._hAlign = "right";
  20.       this._vAlign = "down";
  21.       this._offsetX = 0;
  22.       this._offsetY = 20;
  23.       this._delay = 1000;
  24.       this._duration = 4000;
  25.       this._follow = false;
  26.       this._autoHide = true;
  27.       this._enabled = true;
  28.       this._tipStyle = {textFormat:new TextFormat("Arial Unicode MS",11,0,_global.gUseEmbeddedFont),borderThickness:1,borderColor:13291203,borderAlpha:100,fillColor:16703400,fillAlpha:90,shadowColor:0,shadowAlpha:60,shadowSize:1,shadowOffset:4};
  29.    }
  30.    function checkDelay()
  31.    {
  32.       if(getTimer() > this.startTime + Number(this.getProp("delay")))
  33.       {
  34.          this.createToolTip();
  35.       }
  36.    }
  37.    function createToolTip()
  38.    {
  39.       this.startTime = getTimer();
  40.       this.createField();
  41.       this.createBackground();
  42.       this.createBorder();
  43.       if(this._showShadow)
  44.       {
  45.          this.createShadow();
  46.       }
  47.       this.setPosition();
  48.       this.tip_mc.onEnterFrame = mx.utils.Delegate.create(this,this.checkDuration);
  49.    }
  50.    function checkDuration()
  51.    {
  52.       if(Boolean(this.getProp("follow")))
  53.       {
  54.          this.setPosition();
  55.       }
  56.       if(getTimer() > this.startTime + Number(this.getProp("duration")))
  57.       {
  58.          if(Boolean(this.getProp("autoHide")))
  59.          {
  60.             this.hide();
  61.          }
  62.       }
  63.    }
  64.    function createField()
  65.    {
  66.       this.tip_mc.createTextField("txtField",3,Number(this.getStyle("borderThickness")),Number(this.getStyle("borderThickness")),200,20);
  67.       this.txtField = TextField(this.tip_mc.txtField);
  68.       this.txtField.autoSize = true;
  69.       this.txtField.multiline = true;
  70.       this.txtField.selectable = false;
  71.       this.txtField.html = true;
  72.       this.txtField.setNewTextFormat(TextFormat(this.getStyle("textFormat")));
  73.       this.txtField.htmlText = this.tipText;
  74.       this.txtField.embedFonts = _global.gUseEmbeddedFont;
  75.    }
  76.    function createBackground()
  77.    {
  78.       this.drawRect(this.tip_mc.createEmptyMovieClip("bg_mc",2),this.txtField._x,this.txtField._y,this.txtField._width,this.txtField._height,{color:Number(this.getStyle("fillColor")),alpha:Number(this.getStyle("fillAlpha"))});
  79.    }
  80.    function createBorder()
  81.    {
  82.       var _loc4_ = 0;
  83.       var _loc3_ = 0;
  84.       var _loc6_ = this.txtField._width + Number(this.getStyle("borderThickness")) * 2;
  85.       var _loc5_ = this.txtField._height + Number(this.getStyle("borderThickness")) * 2;
  86.       var _loc2_ = this.tip_mc.createEmptyMovieClip("border_mc",1);
  87.       _loc2_.lineStyle(Number(this.getStyle("borderThickness")),Number(this.getStyle("borderColor")),Number(this.getStyle("borderAlpha")));
  88.       _loc2_.moveTo(_loc4_,_loc3_);
  89.       _loc2_.lineTo(_loc4_ + _loc6_,_loc3_);
  90.       _loc2_.lineTo(_loc4_ + _loc6_,_loc3_ + _loc5_);
  91.       _loc2_.lineTo(_loc4_,_loc3_ + _loc5_);
  92.       _loc2_.lineTo(_loc4_,_loc3_);
  93.    }
  94.    function createShadow()
  95.    {
  96.       this.drawRect(this.tip_mc.createEmptyMovieClip("shadow_mc",0),Number(this.getStyle("shadowOffset")),Number(this.getStyle("shadowOffset")),this.txtField._width + Number(this.getStyle("borderThickness")) * 2 + Number(this.getStyle("shadowSize")) - Number(this.getStyle("shadowOffset")),this.txtField._height + Number(this.getStyle("borderThickness")) * 2 + Number(this.getStyle("shadowSize")) - Number(this.getStyle("shadowOffset")),{color:Number(this.getStyle("shadowColor")),alpha:Number(this.getStyle("shadowAlpha"))});
  97.    }
  98.    function drawRect(mc, x, y, w, h, style)
  99.    {
  100.       mc.moveTo(x,y);
  101.       mc.beginFill(style.color,style.alpha);
  102.       mc.lineTo(x + w,y);
  103.       mc.lineTo(x + w,y + h);
  104.       mc.lineTo(x,y + h);
  105.       mc.lineTo(x,y);
  106.       mc.endFill();
  107.    }
  108.    function setPosition()
  109.    {
  110.       var _loc3_ = Number(this.getProp("offsetX"));
  111.       var _loc2_ = Number(this.getProp("offsetY"));
  112.       if(String(this.getProp("hAlign")) == "left")
  113.       {
  114.          this.tip_mc._x = this.container_mc._xmouse - this.tip_mc._width + _loc3_;
  115.       }
  116.       else if(String(this.getProp("hAlign")) == "right")
  117.       {
  118.          this.tip_mc._x = this.container_mc._xmouse + _loc3_;
  119.       }
  120.       if(String(this.getProp("vAlign")) == "up")
  121.       {
  122.          this.tip_mc._y = this.container_mc._ymouse - this.tip_mc._height + _loc2_;
  123.       }
  124.       else if(String(this.getProp("vAlign")) == "down")
  125.       {
  126.          this.tip_mc._y = this.container_mc._ymouse + _loc2_;
  127.       }
  128.       if(this.container_mc._xmouse - this.tip_mc._width + _loc3_ < 0)
  129.       {
  130.          this.tip_mc._x = this.container_mc._xmouse + Math.max(10,_loc3_);
  131.       }
  132.       if(this.container_mc._xmouse + this.tip_mc._width + _loc3_ > Stage.width)
  133.       {
  134.          this.tip_mc._x = this.container_mc._xmouse - this.tip_mc._width - _loc3_;
  135.       }
  136.       if(this.container_mc._ymouse - this.tip_mc._height + _loc2_ < 0)
  137.       {
  138.          this.tip_mc._y = this.container_mc._ymouse + Math.max(20,_loc2_);
  139.       }
  140.       if(this.container_mc._ymouse + this.tip_mc._height + _loc2_ > Stage.height)
  141.       {
  142.          this.tip_mc._y = this.container_mc._ymouse - this.tip_mc._height - _loc2_;
  143.       }
  144.    }
  145.    function hookEvent(mc, event, handler, scope)
  146.    {
  147.       var prefix = this.hookPrefix;
  148.       mc[prefix + event] = mc[event];
  149.       var args = arguments.slice(4);
  150.       mc[event] = function()
  151.       {
  152.          handler.apply(scope,args);
  153.          mc[prefix + event]();
  154.       };
  155.    }
  156.    function restoreEvent(mc, event)
  157.    {
  158.       mc[event] = mc[this.hookPrefix + event];
  159.    }
  160.    function getProp(prop)
  161.    {
  162.       return this.overrides[prop] == undefined ? this[prop] : this.overrides[prop];
  163.    }
  164.    function getStyle(prop)
  165.    {
  166.       return this.overrides.tipStyle[prop] == undefined ? this.__get__tipStyle()[prop] : this.overrides.tipStyle[prop];
  167.    }
  168.    function addTip(mc, tipText, overrides)
  169.    {
  170.       this.hookEvent(mc,"onRollOver",this.show,this,tipText,overrides);
  171.       this.hookEvent(mc,"onRollOut",this.hide,this);
  172.       this.hookEvent(mc,"onDragOut",this.hide,this);
  173.    }
  174.    function removeTip(mc)
  175.    {
  176.       this.restoreEvent(mc,"onRollOver");
  177.       this.restoreEvent(mc,"onRollOut");
  178.       this.restoreEvent(mc,"onDragOut");
  179.    }
  180.    function show(tipText, overrides)
  181.    {
  182.       this.tipText = tipText;
  183.       this.overrides = overrides;
  184.       if(!Boolean(this.getProp("enabled")))
  185.       {
  186.          return undefined;
  187.       }
  188.       this.startTime = getTimer();
  189.       this.tip_mc = this.container_mc.createEmptyMovieClip("tip_mc",0);
  190.       this.tip_mc.onEnterFrame = mx.utils.Delegate.create(this,this.checkDelay);
  191.    }
  192.    function hide()
  193.    {
  194.       this.tip_mc.removeMovieClip();
  195.    }
  196.    function destroy()
  197.    {
  198.       this.container_mc.removeMovieClip();
  199.    }
  200.    function get hAlign()
  201.    {
  202.       return this._hAlign;
  203.    }
  204.    function set hAlign(newHAlign)
  205.    {
  206.       this._hAlign = newHAlign;
  207.    }
  208.    function get vAlign()
  209.    {
  210.       return this._vAlign;
  211.    }
  212.    function set vAlign(newVAlign)
  213.    {
  214.       this._vAlign = newVAlign;
  215.    }
  216.    function get offsetX()
  217.    {
  218.       return this._offsetX;
  219.    }
  220.    function set offsetX(newOffsetX)
  221.    {
  222.       this._offsetX = newOffsetX;
  223.    }
  224.    function get offsetY()
  225.    {
  226.       return this._offsetY;
  227.    }
  228.    function set offsetY(newOffsetY)
  229.    {
  230.       this._offsetY = newOffsetY;
  231.    }
  232.    function get delay()
  233.    {
  234.       return this._delay;
  235.    }
  236.    function set delay(newDelay)
  237.    {
  238.       this._delay = newDelay;
  239.    }
  240.    function get duration()
  241.    {
  242.       return this._duration;
  243.    }
  244.    function set duration(newDuration)
  245.    {
  246.       this._duration = newDuration;
  247.    }
  248.    function get follow()
  249.    {
  250.       return this._follow;
  251.    }
  252.    function set follow(mode)
  253.    {
  254.       this._follow = mode;
  255.    }
  256.    function get autoHide()
  257.    {
  258.       return this._autoHide;
  259.    }
  260.    function set autoHide(mode)
  261.    {
  262.       this._autoHide = mode;
  263.    }
  264.    function get tipStyle()
  265.    {
  266.       return this._tipStyle;
  267.    }
  268.    function set tipStyle(newTipStyle)
  269.    {
  270.       this._tipStyle = newTipStyle;
  271.    }
  272.    function get enabled()
  273.    {
  274.       return this._enabled;
  275.    }
  276.    function set enabled(mode)
  277.    {
  278.       this._enabled = mode;
  279.    }
  280. }
  281.